package com.yc.book.biz;

import java.sql.SQLException;
import java.util.Map;

import com.yc.book.dao.ReaderDAO;


public class ReaderBiz {
	
	private ReaderDAO dao = new ReaderDAO();
	private static Map<String,Object> loeginedUser;
	
	public Map<String,Object> login(String name, String pwd) throws BizException{
		// 业务逻辑
		if(name == null || name.trim().isEmpty()) {
			throw new BizException("请填写用户名!");
		}
		
		if(pwd == null || pwd.trim().isEmpty()) {
			throw new BizException("请填写密码!");
		}
		
		try {
			Map<String,Object> reader =  dao.selectForLogin(name, pwd);
			if(reader == null) {
				throw new BizException("用户名或密码!");
			}
			// 登录成功之后, 保存该用户
			loeginedUser = reader;
			return reader;
		} catch (SQLException e) {
			throw new BizException("业务异常请联系管理员", e);
		}
	}

	public static Map<String, Object> getLoeginedUser() {
		return loeginedUser;
	}
	
	

}
